#!/bin/bash
#
# Copyright (C) 2017 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
#
# SPDX-License-Identifier: LGPL-2.1-only

CURDIR=$(dirname "$0")/
TESTDIR=$CURDIR/../../../

TESTAPP_PATH="$TESTDIR/utils/testapp"
TESTAPP_STATE_PATH=$(mktemp -u -t "tmp.test_notif_kernel_error_application_state.XXXXXXXXXX")

NUM_TESTS=44

# shellcheck source=../../../utils/utils.sh
source "$TESTDIR/utils/utils.sh"
# shellcheck source=./util_event_generator.sh
source "$CURDIR/util_event_generator.sh"

function test_basic_error_path
{
	kernel_event_generator_run_once_per_transition generate_filter_events \
		"$TESTAPP_STATE_PATH" 10 &
	APP_PID=$!

	"$CURDIR/notification" 1 LTTNG_DOMAIN_KERNEL $APP_PID \
		"$TESTAPP_STATE_PATH"

	kill -SIGUSR2 $APP_PID
	wait $APP_PID 2> /dev/null
}

check_skip_kernel_test &&
{
	plan_skip_all "Skipping all tests."
	exit 0
}

validate_lttng_modules_present

modprobe lttng-test

start_lttng_sessiond_notap

test_basic_error_path

stop_lttng_sessiond_notap
rmmod lttng-test


rm -f "$TESTAPP_STATE_PATH"
